﻿using DevExpress.Utils.Win;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Popup;
using DevExpress.XtraGrid.Demos.util;
using DevExpress.XtraGrid.Editors;
using DevExpress.XtraLayout;
using DiaoPaiDaYin;
using DXApplicationTangche.DTO;
using DXApplicationTangche.DTO.坚山;
using DXApplicationTangche.service;
using DXApplicationTangche.service.redis_service;
using DXApplicationTangche.UC.下单MTO.Service;
using DXApplicationTangche.UC.尺寸;
using DXApplicationTangche.UC.款式异常;
using DXApplicationTangche.UC.款式管理;
using DXApplicationTangche.UC.款式管理.service;
using DXApplicationTangche.UC.订单一览新.辅料.service;
using DXApplicationTangche.UC.订单一览新.辅料.辅料下单;
using DXApplicationTangche.UC.设计点;
using DXApplicationTangche.UC.辅料;
using DXApplicationTangche.UC.销售管理;
using DXApplicationTangche.UC.门店下单.DTO;
using DXApplicationTangche.UC.门店下单.form;
using DXApplicationTangche.UC.门店下单.service;
using DXApplicationTangche.UC.门店下单.下单;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.门店下单
{
    public partial class Frm门店下单选款式新 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        #region 变量
        private XtraUserControlC设计点 XtraUserControlC设计点 { get; set; }
        private List<面料选择> 面料选择s = new List<面料选择>();
        public DTOStyleMeasureItems dTOStyleMeasureItems { get; set; }
        private String categoryId;
        private List<DTO款式备选> DTO款式备选s = new List<DTO款式备选>();
        public List<StyleCategoryDTO> styleCategoryDTOs = new List<StyleCategoryDTO>();
        //private DataTable STYLE_CATEGORY;
        public StyleAccessoryItemsDTO styleAccessoryItemsDTO;//辅料保存用dto
        public List<ContrastForUCDto> contrastForUCDtos = new List<ContrastForUCDto>();
        public List<StyleAccessoryDTO> DTO辅料s = new List<StyleAccessoryDTO>();//辅料保存用dto
        private String 款式类别 { get; set; }
        private String 款式 { get; set; }
        private String 款号 { get; set; }
        private Frm门店统一下单 frm;
        public DTO坚山款式 dto坚山款式 { get; set; }
        public 门店下单选款式Model model = new 门店下单选款式Model();
        private String refOrderId { get; set; }
        private String refOrderNo { get; set; }
        #endregion
        public Frm门店下单选款式新(Frm门店统一下单 frm)
        {
            InitializeComponent();
            this.frm = frm;
            //this.dto坚山款式 = new DTO坚山款式();
            //this.dto坚山款式.刺绣设计点s = new List<string>();
            //this.dto坚山款式.刺绣设计点s = FunctionHelper.JsonDeserialization<List<String>>("[\"4SMT\",\"4SMO\",\"4SMC\",\"4SMP\",\"4SMS\"]");
            //this.STYLE_CATEGORY = StyleService.GetAllSTYLE_CATEGORY();
            this.styleCategoryDTOs = FunctionHelper.JsonDeserialization<List<StyleCategoryDTO>>(RestCall.httpGetMethod(URL.接口url + "/style/getStyleCategoryAll"));
            this.searchLookUpEdit款式类别.Properties.DataSource = this.styleCategoryDTOs;
            this.searchLookUpEdit款式.Properties.DataSource = this.DTO款式备选s;
            this.面料选择s = MTO订单Service.getMaterialOrderIndexAll();
            this.searchLookUpEdit面料.Properties.DataSource = this.面料选择s;
        }
        
        #region 选择面料
        /// <summary>
        /// 绑定清空事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit面料_Popup(object sender, EventArgs e)
        {
            //得到当前SearchLookUpEdit弹出窗体
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clearBtn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        /// <summary>
        /// 点击选择后的行为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit面料View_Click(object sender, EventArgs e)
        {
            var a = this.searchLookUpEdit面料.Properties.View.GetSelectedRows();
            foreach (int rowHandle in a)
            {
                //Frm面料选择.mianliaocd = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "Code").ToString();
                Frm面料选择.mianliaoid = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialId").ToString();
                Frm面料选择.mianliao = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialNameCn").ToString();
                this.model.Dto定制下单.SYTLE_FABRIC_ID = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialId").ToString();
                Frm面料选择.mianliaocd = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialCode").ToString();
                this.model.Dto定制下单.materialCode = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialCode").ToString();
                String MLpicurl = RestCall.httpGetMethod(URL.接口url + "/image/getImagePath?materialCode=" + Frm面料选择.mianliaocd);
                if (String.IsNullOrWhiteSpace(MLpicurl)|| MLpicurl.Contains("no"))
                {
                    this.pictureBox面料图片.Image = DXApplicationTangche.Properties.Resources.SSHIRT;
                }
                else
                {
                    this.pictureBox面料图片.LoadAsync(URL.图片url + URL.面料图片路径 + MLpicurl);
                }
                
                this.textBox成分.Clear();
                this.textBox成分.Text = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialComposition").ToString();
            }
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearBtn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit面料.ToolTip = null;
            searchLookUpEdit面料.EditValue = null;
        }
        /// <summary>
        /// 选完之后的显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit面料_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = Frm面料选择.mianliaocd + ":" + Frm面料选择.mianliao;
        }
        #endregion

        #region 选择款式类别
        /// <summary>
        /// 绑定清空事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit款式类别_Popup(object sender, EventArgs e)
        {
            //得到当前SearchLookUpEdit弹出窗体
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clearBtn款式类别_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        /// <summary>
        /// 点击选择后的行为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit款式类别View_Click(object sender, EventArgs e)
        {
            var a = this.searchLookUpEdit款式类别.Properties.View.GetSelectedRows();
            foreach (int rowHandle in a)
            {
                this.categoryId=this.searchLookUpEdit款式类别.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
                this.款式类别 = this.searchLookUpEdit款式类别.Properties.View.GetRowCellValue(rowHandle, "name").ToString();
                if (this.searchLookUpEdit款式类别.Properties.View.GetRowCellValue(rowHandle, "code").ToString().Contains("STYLE_CATEGORY-"))
                {
                    this.model.Dto定制下单.STYLE_CATEGORY_CD = this.searchLookUpEdit款式类别.Properties.View.GetRowCellValue(rowHandle, "code").ToString();
                }
                else
                {
                    this.model.Dto定制下单.STYLE_CATEGORY_CD = "STYLE_CATEGORY-" + this.searchLookUpEdit款式类别.Properties.View.GetRowCellValue(rowHandle, "code").ToString();
                }
                this.DTO款式备选s = FunctionHelper.JsonDeserialization<List<DTO款式备选>>(RestCall.httpGetMethod(URL.接口url + "/style/getStyleMapByCategory?categoryId=" + this.categoryId));
                this.searchLookUpEdit款式.Properties.DataSource = this.DTO款式备选s;
                this.gridView4.RefreshData();
                //this.布辅料控件();
                //this.SYTLE_FABRIC_ID = this.SYTLE_FABRIC_ID + this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "MATERIAL_ID").ToString() + ",";
                //this.面料NA = this.面料NA + this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "MATERIAL_NAME_CN").ToString() + ",";
                //this.dto无订单打印.materials_id //  no
                //    = this.searchLookUpEdit1.Properties.View.GetRowCellValue(rowHandle, "id").ToString();//id 是 Value Member
                //this.dto无订单打印.materials_cd //  no
                //    = this.searchLookUpEdit1.Properties.View.GetRowCellValue(rowHandle, "materialCode").ToString();//id 是 Value Member
                //this.dto无订单打印.materialComposition = this.searchLookUpEdit1.Properties.View.GetRowCellValue(rowHandle, "materialComposition").ToString();
                //this.dto无订单打印.materialNameCn = this.searchLookUpEdit1.Properties.View.GetRowCellValue(rowHandle, "materialNameCn").ToString();
            }
            //this.mianliaoid.Text = this.dto无订单打印.materials_id;
            //this.mianliaocd.Text = this.dto无订单打印.materials_cd;
            //this.chengfen.Text = this.dto无订单打印.materialComposition;
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearBtn款式类别_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit款式类别.ToolTip = null;
            searchLookUpEdit款式类别.EditValue = null;
        }
        /// <summary>
        /// 选完之后的显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit款式类别_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.款式类别;
        }
        #endregion

        #region 选择款式
        /// <summary>
        /// 绑定清空事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit款式_Popup(object sender, EventArgs e)
        {
            //得到当前SearchLookUpEdit弹出窗体
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clearBtn款式_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        /// <summary>
        /// 点击选择后的行为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit款式View_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            this.款式 = FunctionHelper.GetgridViewValue(this.searchLookUpEdit款式.Properties.View, e.RowHandle, "name").ToString();
            this.款号 = FunctionHelper.GetgridViewValue(this.searchLookUpEdit款式.Properties.View, e.RowHandle, "code").ToString();
            this.textBox款号.Text = this.款号;
            this.textBox款名.Text = this.款式;

            this.model.Dto定制下单.Style_Id = FunctionHelper.GetgridViewValue(this.searchLookUpEdit款式.Properties.View, e.RowHandle, "styleId").ToString();
            this.model.Dto定制下单.Dto设计点s.Clear();
            this.XtraUserControlC设计点 = new XtraUserControlC设计点(this.款号);
            this.model.Dto定制下单.Dto设计点s = this.XtraUserControlC设计点.Dto设计点s;
            this.initNavigationPage(this.XtraUserControlC设计点);
            //  选中款式
            StyleInfoDto styleInfoDto = 款式Service.getStyleInfoByStyleId(Convert.ToInt32(this.model.Dto定制下单.Style_Id));
            this.model.Dto定制下单.build选中款式(
                                    styleInfoDto.sysStyleId.ToString(),
                                    styleInfoDto.styleCategoryCd,
                                    styleInfoDto.styleFitCd,
                                    styleInfoDto.styleSizeGroupCd,
                                    styleInfoDto.sytleFabricId,
                                    styleInfoDto.styleMakeType
                                    );
            this.chicun01.Items.Clear();
            List<String> 尺码 = new List<string>();
            尺码 = FunctionHelper.JsonDeserialization<List<String>>(RestCall.httpGetMethod(URL.接口url + "/MTOOrder/customized/findSizeCdByStyleNameCn?styleNameCn=" + this.款号));
            foreach(String str in 尺码)
            {
                this.chicun01.Items.Add(str);
            }
        }
        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearBtn款式_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit款式.ToolTip = null;
            searchLookUpEdit款式.EditValue = null;
        }
        /// <summary>
        /// 选完之后的显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit款式_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.款式;
        }
        #endregion

        private void barEditItemNumber_EditValueChanged(object sender, EventArgs e)
        {
            //this.model.Dto定制下单.build数量(this.barEditItem数量.EditValue.ToString());
        }
        private void gridViewSize_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            this.model.buildCountSize(e.RowHandle, e.Column.FieldName, e.Value.ToString());    //  尺寸计算

            MeasureItemDTO dTOMeasureItem = new MeasureItemDTO(this.model.尺寸呈现[e.RowHandle]);
            RestCall.PostHttp(URL.接口url + "/MTOOrder/customized/saveMeasureItem?sessionId=" + this.dTOStyleMeasureItems.sessionId, FunctionHelper.JsonSerialization(dTOMeasureItem));
            this.gridControlSize.DataSource = this.model.尺寸呈现;
            String str = FunctionHelper.JsonSerialization(this.model.尺寸呈现);
            this.gridControlSize.Refresh();
        }
        private void gridViewSize_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            //e.Appearance.BackColor = Color.NavajoWhite;
            try
            {
                if (e.Column.Name == "colGarment")
                {
                    if (this.model.尺寸呈现[e.RowHandle].OUT_VALUE > this.model.尺寸呈现[e.RowHandle].leastReasonable)
                    {
                        //该行数据的该列的值不为空时时,其背景色为Red
                        e.Appearance.BackColor = Color.Red;//设置单元格变色
                                                           //e.Column.AppearanceCell.BackColor = Color.Red;//设置数据列变色
                    }
                    else if (this.model.尺寸呈现[e.RowHandle].IN_VALUE > this.model.尺寸呈现[e.RowHandle].maxReasonable)
                    {
                        //该行数据的该列的值不为空时时,其背景色为Red
                        e.Appearance.BackColor = Color.Green;//设置单元格变色
                                                             //e.Column.AppearanceCell.BackColor = Color.Red;//设置数据列变色
                    }
                    else
                    {
                        //e.Appearance.BackColor = Color.LightGray;
                    }
                }
            }
            catch { }
        }
        private void chicun01_SelectedIndexChanged(object sender, EventArgs e)
        {
            //this.model.build选中尺寸(this.chicun01.Text.Trim(), this.model.Dto定制下单.Style_Id, Frm定制下单修改尺寸.stylesizedt);
            this.model.Dto定制下单.STYLE_SIZE_CD = "IGS_GROUP_SIZE-" + this.chicun01.Text.Trim();
            String json = RestCall.httpGetMethod(URL.接口url + "/MTOOrder/customized/generateStyleMeasureItemsByStyleNameCn?SIZE_CD=" + this.model.Dto定制下单.STYLE_SIZE_CD + "&styleNameCn=" + this.款号 + "&categoryId=" + this.categoryId);
            this.dTOStyleMeasureItems = FunctionHelper.JsonDeserialization<DTOStyleMeasureItems>(json);
            this.treeList尺寸.DataSource = this.dTOStyleMeasureItems.measureItemDTOS;
            this.treeList尺寸.Refresh();
        }
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("确认保存吗？", "保存", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dialogResult == DialogResult.Yes)
            {
                if (!String.IsNullOrEmpty(this.XtraUserControlC设计点.vo刺绣内容.optionValue))
                {
                    if (String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣位置.itemCd)
                        || String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣大小.itemCd)
                        || String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣字体.itemCd)
                        || String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣颜色.itemCd))
                    {
                        MessageBox.Show("请将刺绣位置、大小、字体、颜色选择完全");
                        return;
                    }
                }
                if (!String.IsNullOrEmpty(this.XtraUserControlC设计点.vo刺绣内容.optionValue)
                    && !String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣位置.itemCd)
                    && !String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣大小.itemCd)
                    && !String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣字体.itemCd)
                    && !String.IsNullOrWhiteSpace(this.XtraUserControlC设计点.vo刺绣颜色.itemCd))
                {
                    this.model.Dto定制下单.Dto设计点s.Add(new DTODesignPoints(this.XtraUserControlC设计点.vo刺绣位置));
                    this.model.Dto定制下单.Dto设计点s.Add(new DTODesignPoints(this.XtraUserControlC设计点.vo刺绣大小));
                    this.model.Dto定制下单.Dto设计点s.Add(new DTODesignPoints(this.XtraUserControlC设计点.vo刺绣字体));
                    this.model.Dto定制下单.Dto设计点s.Add(new DTODesignPoints(this.XtraUserControlC设计点.vo刺绣颜色));
                    this.model.Dto定制下单.Dto设计点s.Add(new DTODesignPoints(this.XtraUserControlC设计点.vo刺绣内容));
                }


                this.model.Dto定制下单.refOrderId = this.refOrderId;
                this.model.Dto定制下单.refOrderNo = this.refOrderNo;

                this.model.Dto定制下单.STYLE_NAME_CN = this.textBox款号.Text + " " + this.textBox款名.Text;
                this.model.Dto定制下单.Delete空设计点();
                this.model.Dto定制下单.build数量(this.numericUpDown数量.Value.ToString());

                this.model.build尺寸保存(this.dTOStyleMeasureItems);//尺寸保存

                try
                {
                    //  校验订单
                    this.model.verify订单();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                //辅料保存
                this.styleAccessoryItemsDTO = new StyleAccessoryItemsDTO(this.model.Dto定制下单.STYLE_NAME_CN, this.contrastForUCDtos);
                this.model.Dto定制下单.sessionId = this.model.sessionId;

                this.frm.buildOrderModel(
                    this.model.Dto定制下单,    //  更新辅料
                    this.styleAccessoryItemsDTO, 
                    DXApplicationTangche.model.Enum订单类型.春衫订单
                    );
                this.frm.refreshGridControl();

                MessageBox.Show("保存成功");
                this.Close();
            }
        }


        private void numericUpDown数量_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((NumericUpDown)sender).Text.Trim().IndexOf('.') > -1)
            {
                if (((NumericUpDown)sender).Text.Trim().Substring(((NumericUpDown)sender).Text.Trim().IndexOf('.') + 1).Length >= 0)//定义小数位
                {
                    if (!char.IsDigit(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                }
            }
        }

        /// <summary>
        /// 初始化导航
        /// </summary>
        /// <param name="uC"></param>
        private void initNavigationPage(XtraUserControl uC)
        {
            uC.Dock = DockStyle.Fill;
            this.dockPanel设计点.Controls.Clear();
            this.dockPanel设计点.Controls.Add(uC);
        }

        private void numericUpDown1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((NumericUpDown)sender).Text.Trim().IndexOf('.') > -1)
            {
                if (((NumericUpDown)sender).Text.Trim().Substring(((NumericUpDown)sender).Text.Trim().IndexOf('.') + 1).Length >= 0)//定义小数位
                {
                    if (!char.IsDigit(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                }
            }
        }

        private void treeList尺寸_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)
        {
            //if (e.Column == treeListColumn试样衣尺寸)
            //{
            //    if (this.dTOStyleMeasureItems.hasGarmentSize(this.treeList尺寸.FocusedNode["id"].ToString()))
            //    {
            //        e.Appearance.BackColor = Color.Red;
            //        e.Appearance.Options.UseBackColor = true;
            //    }
            //    else
            //    {
                    
            //    }
            //}
        }

        private void treeList尺寸_CellValueChanged(object sender, DevExpress.XtraTreeList.CellValueChangedEventArgs e)
        {
            try
            {
                this.dTOStyleMeasureItems.build算(this.treeList尺寸.FocusedNode["id"].ToString(), e.Column.FieldName, e.Value.ToString());
                this.treeList尺寸.DataSource = this.dTOStyleMeasureItems.measureItemDTOS;
                this.treeList尺寸.Refresh();
            }
            catch
            {
            }
        }

        private void treeList尺寸_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
        {
            try
            {
                if (this.treeList尺寸.FocusedColumn == this.treeListColumn加 || this.treeList尺寸.FocusedColumn == this.treeListColumn减)
                {
                    if (!FunctionHelper.IsFloat(e.Value.ToString()) || !FunctionHelper.Is半角(e.Value.ToString()))
                    {
                        e.ErrorText = "输入格式不正确！";
                        e.Valid = false;
                        return;
                    }
                }
            }
            catch
            {

            }
        }

        private void pictureBox备注图片1_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "gif,jpg,png|*.gif;*.jpg;*.png;*.jpeg";
            ofd.Title = "请选择图片文件";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (备注图片 rp in this.model.Dto定制下单.备注图片s)
                {
                    if ("1".Equals(rp.ID))
                    {
                        this.model.Dto定制下单.备注图片s.Remove(rp);
                        break;
                    }
                }
                this.model.Dto定制下单.备注图片s.Add(new 备注图片("1", Image.FromFile(ofd.FileName), "", ofd.FileName));
                this.pictureBox备注图片1.Image = Image.FromFile(ofd.FileName);
            }
        }

        private void pictureBox备注图片2_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "gif,jpg,png|*.gif;*.jpg;*.png;*.jpeg";
            ofd.Title = "请选择图片文件";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (备注图片 rp in this.model.Dto定制下单.备注图片s)
                {
                    if ("2".Equals(rp.ID))
                    {
                        this.model.Dto定制下单.备注图片s.Remove(rp);
                        break;
                    }
                }
                this.model.Dto定制下单.备注图片s.Add(new 备注图片("2", Image.FromFile(ofd.FileName), "", ofd.FileName));
                this.pictureBox备注图片2.Image = Image.FromFile(ofd.FileName);
            }
        }

        private void pictureBox备注图片3_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "gif,jpg,png|*.gif;*.jpg;*.png;*.jpeg";
            ofd.Title = "请选择图片文件";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (备注图片 rp in this.model.Dto定制下单.备注图片s)
                {
                    if ("3".Equals(rp.ID))
                    {
                        this.model.Dto定制下单.备注图片s.Remove(rp);
                        break;
                    }
                }
                this.model.Dto定制下单.备注图片s.Add(new 备注图片("3", Image.FromFile(ofd.FileName), "", ofd.FileName));
                this.pictureBox备注图片3.Image = Image.FromFile(ofd.FileName);
            }
        }

        private void richTextBox套号备注_TextChanged(object sender, EventArgs e)
        {
            this.model.build备注(this.richTextBox套号备注.Text);
        }

        private void 删除备注图片1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (备注图片 rp in this.model.Dto定制下单.备注图片s)
            {
                if (1.Equals(rp.ID))
                {
                    this.model.Dto定制下单.备注图片s.Remove(rp);
                    this.pictureBox备注图片1.Image = null;
                    break;
                }
            }
        }

        private void 删除备注图片2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (备注图片 rp in this.model.Dto定制下单.备注图片s)
            {
                if (2.Equals(rp.ID))
                {
                    this.model.Dto定制下单.备注图片s.Remove(rp);
                    this.pictureBox备注图片2.Image = null;
                    break;
                }
            }
        }

        private void 删除备注图片3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (备注图片 rp in this.model.Dto定制下单.备注图片s)
            {
                if (3.Equals(rp.ID))
                {
                    this.model.Dto定制下单.备注图片s.Remove(rp);
                    this.pictureBox备注图片3.Image = null;
                    break;
                }
            }
        }

        //选择返单号
        private void gridView历史订单_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            this.refOrderId = FunctionHelper.GetgridViewValue(
                                    this.gridView历史订单,
                                    this.gridView历史订单.FocusedRowHandle,
                                    "orderId"
                                    );
            this.refOrderNo = FunctionHelper.GetgridViewValue(
                                    this.gridView历史订单, 
                                    this.gridView历史订单.FocusedRowHandle,
                                    "orderNo"
                                    );
            this.textBox返单号.Text = this.refOrderNo;
        }

        private void treeList尺寸_DoubleClick(object sender, EventArgs e)
        {
            new Form尺寸更改(
                this.dTOStyleMeasureItems, 
                this.treeList尺寸.FocusedNode["id"].ToString())
                .ShowDialog();
        }
    }
}
